package com.OrderingSystem.controller.seller;



import com.OrderingSystem.pojo.Loginlog;
import com.OrderingSystem.pojo.ProductCategory;
import com.OrderingSystem.service.ILoginlogService;
import com.OrderingSystem.utils.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 * @author bruce
 */
@Api(tags = "登录日志接口")
@RestController
@ApiResponses({
        @ApiResponse(code = 200, message = "操作", response = ProductCategory.class),
        @ApiResponse(code = 400, message = "参数错误"),
        @ApiResponse(code = 403, message = "权限被禁止"),
        @ApiResponse(code = 500, message = "服务器内部错误")
})
@RequestMapping("/loginlog")
@Slf4j
public class LoginlogController {

    @Resource
    ILoginlogService loginlogService;


    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "查询当前登录用户的登录日志", notes = "查询当前登录用户的登录日志")
    @GetMapping("selectPage")
    public Result selectPage(@RequestParam("pageNum") Integer pageNum,
                             @RequestParam("pageSize") Integer pageSize) {
        //使用分页插件
        PageHelper.startPage(pageNum, pageSize);
        //查询数据库，需要用到like查询
        List<Loginlog> list = loginlogService.list(new QueryWrapper<Loginlog>().orderByDesc("id"));
        //封装一下查询的结果集
        PageInfo<Loginlog> pageInfo = PageInfo.of(list);
        return Result.success(pageInfo);
    }


}
